﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSP.Receipts.DataModel
{
    public class ReceiptDbInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<ReceiptContext>
    {
        protected override void Seed(ReceiptContext context)
        {
            base.Seed(context);

            context.Categories.Add(new Category { Title = "Italienisch" });
            context.Categories.Add(new Category { Title = "Pasta" });
            context.Categories.Add(new Category { Title = "Gutbürgerlich" });
            var category = new Category { Title = "Allgemein" };
            context.Categories.Add(category);

            var user = new User() { FirstName = "Andreas", LastName = "Gräfe", Username = "katarch", Password = "test", EMail = "andreasgraefe@gmail.com" };
            context.Users.Add(user);

            for (int i = 0; i < 10; i++)
            {
                var picture = new Picture(){ CreationDate=DateTime.Now, Title="Picture " + i.ToString()};
                picture.Image = System.IO.File.ReadAllBytes("c:\\temp\\bild.jpg");

                var receipt = new Receipt() { CreationDate = DateTime.Now, Owner=user, Title = String.Format("Mein Rezept No. {0}", i), Url = "http://www.test.de", ReceiptText = "Lorem ipsum", Category = category };
                receipt.ReceiptPictures.Add(picture);
                
                context.Receipts.Add(receipt);
            }
            context.SaveChanges();
        }
    }
}
